package fictional.Common;

import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;

// import org.jdesktop.application.Application.ExitListener;

public abstract class SocialElement<T extends SocialItem> implements Iterable<T>{
	protected SortedSet<T> collection;
	protected CharacterItem character;
	
	protected SocialElement() {
		collection = new TreeSet<T>();
	}
	
	protected SortedSet<T> getCollection() {
		return collection;
	}
	
	protected void setCollection(SortedSet<T> set) {
		collection = set;
	}
	
	public CharacterItem getCharacter() {
		return character;
	}
	
	public void setCharacter(CharacterItem character) {
		this.character = character;
	}
	
	protected void addItem(T item) {
		if (!collection.contains(item)) 
			collection.add(item);
	}
	
	protected void removeItem(T item) {
		if (collection.contains(item))
			collection.remove(item);
	}
	
	@Override
	public Iterator<T> iterator() {
		return collection.iterator();
	}	
}